<!DOCTYPE html>






<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />


















  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="chrome,vue,爬虫,axios," />










<meta name="description" content="chrome扩展的练习学习晋级记录">
<meta name="keywords" content="chrome,vue,爬虫,axios">
<meta property="og:type" content="article">
<meta property="og:title" content="chrome扩展开发">
<meta property="og:url" content="https://zhangyuhan2016.gitee.io/2018/01/02/chrome-extension/index.html">
<meta property="og:site_name" content="zhangyuhan2016">
<meta property="og:description" content="chrome扩展的练习学习晋级记录">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://zhangyuhan2016.gitee.io/images/chrome-1.gif">
<meta property="og:image" content="https://zhangyuhan2016.gitee.io/images/book_01.png">
<meta property="og:image" content="https://zhangyuhan2016.gitee.io/images/book.gif">
<meta property="og:updated_time" content="2018-03-21T08:59:13.932Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="chrome扩展开发">
<meta name="twitter:description" content="chrome扩展的练习学习晋级记录">
<meta name="twitter:image" content="https://zhangyuhan2016.gitee.io/images/chrome-1.gif">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zhangyuhan2016.gitee.io/2018/01/02/chrome-extension/"/>





  <title>chrome扩展开发 | zhangyuhan2016</title>









</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<header style="position: fixed;z-index: 99999999;background-color: #eee;width: 100%;text-align: center;">
    <h3>感谢您的关注，最新博客已迁移至 <mark style="background-color: #07c160;padding: 4px;"><a style="color: #fff;" href="https://blog.hi-zhang.com" target="_blank">blog.hi-zhang.com</a></mark> </h3>
</header>






  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">


    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">zhangyuhan2016</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>

        <p class="site-subtitle"></p>

  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">



    <ul id="menu" class="menu">


        <li class="menu-item menu-item-home">
          <a href="/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />

            首页
          </a>
        </li>


        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />

            标签
          </a>
        </li>


        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />

            归档
          </a>
        </li>



    </ul>



</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">


  <div id="posts" class="posts-expand">








  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">



  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zhangyuhan2016.gitee.io/2018/01/02/chrome-extension/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="zhangyuhan2016">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars3.githubusercontent.com/u/18086072?s=460&v=4">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="zhangyuhan2016">
    </span>


      <header class="post-header">



          <h1 class="post-title" itemprop="name headline">chrome扩展开发</h1>


        <div class="post-meta">
          <span class="post-time">

              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>

                <span class="post-meta-item-text">发表于</span>

              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-02T10:10:12+08:00">
                2018-01-02
              </time>



              <span class="post-meta-divider">|</span>



              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>

                <span class="post-meta-item-text">更新于&#58;</span>

              <time title="更新于" itemprop="dateModified" datetime="2018-03-21T16:59:13+08:00">
                2018-03-21
              </time>

          </span>





              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/01/02/chrome-extension/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/01/02/chrome-extension/" itemprop="commentCount"></span>
                </a>
              </span>





             <span id="/2018/01/02/chrome-extension/" class="leancloud_visitors" data-flag-title="chrome扩展开发">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>

                 <span class="post-meta-item-text">阅读次数&#58;</span>

                 <span class="leancloud-visitors-count"></span>
             </span>





            <div class="post-wordcount">


                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>

                  <span class="post-meta-item-text">字数统计&#58;</span>

                <span title="字数统计">
                  1,007
                </span>



                <span class="post-meta-divider">|</span>



                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>

                  <span class="post-meta-item-text">阅读时长 &asymp;</span>

                <span title="阅读时长">
                  4
                </span>

            </div>




        </div>
      </header>





    <div class="post-body" itemprop="articleBody">





        <blockquote class="blockquote-center"><p>chrome扩展的练习学习晋级记录</p>
</blockquote>
<a id="more"></a>
<p>参考资料</p>
<ol>
<li><a href="http://www.ituring.com.cn/book/miniarticle/60134" target="_blank" rel="noopener">我的第一个Chrome扩展</a></li>
<li><a href="https://www.kancloud.cn/wizardforcel/chrome-doc/98796" target="_blank" rel="noopener">Chrome 扩展开发文档</a><h2 id="二维码生成器"><a href="#二维码生成器" class="headerlink" title="二维码生成器"></a>二维码生成器</h2></li>
</ol>
<ul>
<li style="list-style: none"><input type="checkbox" checked> 获取当前标签的URL,通过jquery.qrcode.js绘制二维码</li>
<li style="list-style: none"><input type="checkbox"> 右键选中URL生成二维码</li>
</ul>
<p><img src="/images/chrome-1.gif" alt="chrome-ed"></p>
<h3 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h3><ul>
<li><a href="https://github.com/jeromeetienne/jquery-qrcode" target="_blank" rel="noopener">jquery.qrcode.js</a></li>
</ul>
<h3 id="Code"><a href="#Code" class="headerlink" title="Code"></a>Code</h3><p><strong>js</strong><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 获取当前标签的URL */</span></span><br><span class="line">chrome.tabs.query(&#123;</span><br><span class="line">  active: <span class="literal">true</span>,</span><br><span class="line">  lastFocusedWindow: <span class="literal">true</span></span><br><span class="line">&#125;, <span class="function"><span class="keyword">function</span> (<span class="params">tabs</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> url = tabs[<span class="number">0</span>].url</span><br><span class="line">  drawCode(url)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 绘制二维码 */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">drawCode</span> (<span class="params">url</span>) </span>&#123;</span><br><span class="line">  $(<span class="string">'.reload input'</span>).val(url)</span><br><span class="line">  $(<span class="string">'#qrcode'</span>).html(<span class="string">''</span>).qrcode(&#123;<span class="attr">width</span>: <span class="number">200</span>, <span class="attr">height</span>: <span class="number">200</span>, <span class="attr">text</span>: url&#125;)</span><br><span class="line">&#125;</span><br><span class="line">$(<span class="string">'button'</span>).on(<span class="string">'click'</span>,<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  drawCode($(<span class="string">'input'</span>).val())</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></p>
<p><strong>右键菜单设置</strong><br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">chrome.contextMenus.create(&#123;</span><br><span class="line">  <span class="string">'type'</span>:<span class="string">'normal'</span>,</span><br><span class="line">  <span class="string">'title'</span>:<span class="string">'生成二维码'</span>,</span><br><span class="line">  <span class="string">'onclick'</span>: showCode</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">showCode</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="comment">/**/</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 离开popup改变icon */</span></span><br><span class="line">chrome.windows.onFocusChanged.addListener(<span class="function"><span class="keyword">function</span>(<span class="params">window</span>) </span>&#123;</span><br><span class="line">  chrome.browserAction.setIcon(&#123;<span class="attr">path</span>: <span class="string">'/images/qrcode.png'</span>&#125;)</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<p><strong>manifest.json</strong><br><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"manifest_version"</span>: <span class="number">2</span>,</span><br><span class="line">  <span class="attr">"name"</span>: <span class="string">"二维码生成器"</span>,</span><br><span class="line">  <span class="attr">"version"</span>: <span class="string">"1.0"</span>,</span><br><span class="line">  <span class="attr">"description"</span>: <span class="string">"利用二维码库制作的二维码生成器"</span>,</span><br><span class="line">  <span class="attr">"icons"</span>: &#123;</span><br><span class="line">    <span class="attr">"128"</span>: <span class="string">"images/qrcode.png"</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">"browser_action"</span>: &#123;</span><br><span class="line">    <span class="attr">"default_icon"</span>: &#123;</span><br><span class="line">      <span class="attr">"19"</span>: <span class="string">"images/qrcode.png"</span>,</span><br><span class="line">      <span class="attr">"38"</span>: <span class="string">"images/qrcode-hover.png"</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">"default_title"</span>: <span class="string">"生成二维码"</span>,</span><br><span class="line">    <span class="attr">"default_popup"</span>: <span class="string">"index.html"</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">"permissions"</span>: [</span><br><span class="line">    <span class="string">"tabs"</span>,</span><br><span class="line">    <span class="string">"activeTab"</span>,</span><br><span class="line">    <span class="string">"contextMenus"</span></span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">"background"</span>: &#123;</span><br><span class="line">    <span class="attr">"scripts"</span>: [</span><br><span class="line">      <span class="string">"js/background.js"</span></span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="小说txt下载和本地txt阅读"><a href="#小说txt下载和本地txt阅读" class="headerlink" title="小说txt下载和本地txt阅读"></a>小说txt下载和本地txt阅读</h2><p>在学习node爬虫的时候,突然有一个想法<br>浏览器端实现一个爬虫可不可以呢？</p>
<p>说着咱就开始写,我准备用扩展程序的背景页来做,然后发现跨域<br>后续又想到可以注入脚本,于是打开小说网站的目录页,准备和node爬虫用一样的方法</p>
<ul>
<li><p>第一步  获取小说的目录</p>
<p>  获取目录以后那就开始请求HTML吧,那就用axios来整</p>
</li>
<li><p>第二步 获取HTML里的内容</p>
<p>  没有浏览器端的cheerio,我该怎么获取里面的dom</p>
<p>  创建一个节点,然后挂在body里,ifarme行不,然后就可以使用jQ来取内容</p>
<p>  啊哈哈,我真是太棒了,然而事情并不简单…</p>
<p>  经过一系列不忍回首的敲打,我选择直接正则匹配内容,通过匹配div的ID、Name取到了文章内容</p>
</li>
<li><p>第三步 写入文档</p>
<p>  啊,怎么创建一个文档呢,经过不辞幸苦的搜索找到了<a href="https://developer.mozilla.org/zh-CN/docs/Web/API/URL/createObjectURL" target="_blank" rel="noopener">createObjectURL</a><br>  后续的事情一定很简单了吧,无脑拉取输出</p>
<p>  但是网站访问限制,请求并发的问题也避不过去呀</p>
</li>
<li><p>后续</p>
<p>  一个网站怎么够呢,我的目标是星辰大海</p>
<p>  这时候问题就让人难以抉择了,网站的内容目录ID各不相同</p>
<p>  那简单,每个host作为一个key,写写规则存到本地不就行了,在弄个分享规则到云上,岂不美滋滋</p>
<p>  可是不想改代码呀…</p>
<p>  就选了几个目录内容差不多的网址捏一捏,😄</p>
</li>
<li><p>本地小说阅读</p>
<p>  下载完了怎么看呢？总不能用文本看吧,那咱再来弄个阅读器</p>
<p>  说是阅读器,其实也是注入脚本和样式在file网址下,右键一下,发现浏览器打开文档在<code>pre</code>,那就来改造吧</p>
</li>
</ul>
<ul>
<li><p>生成目录</p>
<p>  通过正则匹配第N章 xxx的,然后给他高亮,这时候我又想,那刚才写入的时候可以直接标记一下文章章节.</p>
<p>  当然你知道的,我懒…</p>
</li>
<li><p>自动翻页</p>
<p>  一开始是通过top值滚动,这样滚起来有点尬尬的<br>  就换成tranform加过渡来翻页<br>  效果还是有点瑕疵,看的时间久了眼花</p>
</li>
<li><p>设置间距颜色什么的</p>
<p>  这个很简单,但是找到合适的配色不容易,简单扒了下起点的配色</p>
</li>
</ul>
<p>这个项目优化的点还很多,后续再更新</p>
<p><img src="/images/book_01.png" alt="效果图"><br><img src="/images/book.gif" alt="效果图"></p>
<p><a href="https://github.com/zhangyuhan2016/book-down-read/releases" target="_blank" rel="noopener">book-down-read</a></p>
<h2 id="使用vue开发"><a href="#使用vue开发" class="headerlink" title="使用vue开发"></a>使用vue开发</h2><p>可以把vue项目npm run build 以后,在<strong>manifest.json</strong>修改<strong>default_popup</strong>的入口为打包后的页面</p>
<h2 id="国内安装-chrome扩展"><a href="#国内安装-chrome扩展" class="headerlink" title="国内安装 chrome扩展"></a>国内安装 chrome扩展</h2><ul>
<li><a href="https://chrome-extension-downloader.com" target="_blank" rel="noopener">1</a></li>
<li><a href="https://www.crx4chrome.com/" target="_blank" rel="noopener">2</a><br>下载完成后打开扩展程序<code>chrome://extensions/</code>勾选开发模式,将下载的扩展拖入安装</li>
</ul>


    </div>







      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">




      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/zfb.png" alt="zhangyuhan2016 支付宝"/>
        <p>支付宝</p>
      </div>




  </div>
</div>

      </div>




    <footer class="post-footer">

        <div class="post-tags">

            <a href="/tags/chrome/" rel="tag">chrome</a>

            <a href="/tags/vue/" rel="tag">vue</a>

            <a href="/tags/爬虫/" rel="tag">爬虫</a>

            <a href="/tags/axios/" rel="tag">axios</a>

        </div>







        <div class="post-nav">
          <div class="post-nav-next post-nav-item">

              <a href="/2017/12/29/vue-demo/" rel="next" title="vue小组件制造之路">
                <i class="fa fa-chevron-left"></i> vue小组件制造之路
              </a>

          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">

              <a href="/2018/01/30/Learning-TypeScript/" rel="prev" title="TypeScript学习记录">
                TypeScript学习记录 <i class="fa fa-chevron-right"></i>
              </a>

          </div>
        </div>




    </footer>
  </div>



  </article>



    <div class="post-spread">

    </div>
  </div>


          </div>






    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>





        </div>



  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">

    <div class="sidebar-inner">




        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>


      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">

              <img class="site-author-image" itemprop="image"
                src="https://avatars3.githubusercontent.com/u/18086072?s=460&v=4"
                alt="zhangyuhan2016" />

              <p class="site-author-name" itemprop="name">zhangyuhan2016</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">


              <div class="site-state-item site-state-posts">

                <a href="/archives/">

                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>







              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">30</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>


          </nav>



          <div class="links-of-author motion-element">


                <span class="links-of-author-item">
                  <a href="https://github.com/zhangyuhan2016" target="_blank" title="GitHub">

                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>


          </div>








        </div>
      </section>


      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">






              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#二维码生成器"><span class="nav-number">1.</span> <span class="nav-text"><a href="#&#x4E8C;&#x7EF4;&#x7801;&#x751F;&#x6210;&#x5668;" class="headerlink" title="&#x4E8C;&#x7EF4;&#x7801;&#x751F;&#x6210;&#x5668;"></a>&#x4E8C;&#x7EF4;&#x7801;&#x751F;&#x6210;&#x5668;</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#参考资料"><span class="nav-number">1.1.</span> <span class="nav-text"><a href="#&#x53C2;&#x8003;&#x8D44;&#x6599;" class="headerlink" title="&#x53C2;&#x8003;&#x8D44;&#x6599;"></a>&#x53C2;&#x8003;&#x8D44;&#x6599;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Code"><span class="nav-number">1.2.</span> <span class="nav-text"><a href="#Code" class="headerlink" title="Code"></a>Code</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#小说txt下载和本地txt阅读"><span class="nav-number">2.</span> <span class="nav-text"><a href="#&#x5C0F;&#x8BF4;txt&#x4E0B;&#x8F7D;&#x548C;&#x672C;&#x5730;txt&#x9605;&#x8BFB;" class="headerlink" title="&#x5C0F;&#x8BF4;txt&#x4E0B;&#x8F7D;&#x548C;&#x672C;&#x5730;txt&#x9605;&#x8BFB;"></a>&#x5C0F;&#x8BF4;txt&#x4E0B;&#x8F7D;&#x548C;&#x672C;&#x5730;txt&#x9605;&#x8BFB;</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用vue开发"><span class="nav-number">3.</span> <span class="nav-text"><a href="#&#x4F7F;&#x7528;vue&#x5F00;&#x53D1;" class="headerlink" title="&#x4F7F;&#x7528;vue&#x5F00;&#x53D1;"></a>&#x4F7F;&#x7528;vue&#x5F00;&#x53D1;</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#国内安装-chrome扩展"><span class="nav-number">4.</span> <span class="nav-text"><a href="#&#x56FD;&#x5185;&#x5B89;&#x88C5;-chrome&#x6269;&#x5C55;" class="headerlink" title="&#x56FD;&#x5185;&#x5B89;&#x88C5; chrome&#x6269;&#x5C55;"></a>&#x56FD;&#x5185;&#x5B89;&#x88C5; chrome&#x6269;&#x5C55;</span></a></li></ol></div>


          </div>
        </section>
      <!--/noindex-->




    </div>
    <div class="post-block page my-thanks">
        <div class="my-title">致谢</div>
        <div class="thanks">Hexo</div>
        <div class="thanks">Next & Gemini</div>
        <div class="thanks">Gitee</div>
    </div>
  </aside>



      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">









      </div>
    </footer>


      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>

      </div>




  </div>



<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>



























    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>




    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>




    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>




    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>




    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>




    <script type="text/javascript" src="/lib/three/three.min.js"></script>




    <script type="text/javascript" src="/lib/three/canvas_lines.min.js"></script>






  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>







  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>




  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>






  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>









      <script id="dsq-count-scr" src="https://.disqus.com/count.js" async></script>



      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://zhangyuhan2016.gitee.io/2018/01/02/chrome-extension/';
          this.page.identifier = '2018/01/02/chrome-extension/';
          this.page.title = 'chrome扩展开发';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>






























  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>

  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: true,
        notify: false,
        appId: 'xxTmc7jwpAd2bWhmkKOI7IGY-gzGzoHsz',
        appKey: 'glPUiD8ljbJsKYhBg5E0ghII',
        placeholder: '说点什么呗 ヾﾉ≧∀≦)o',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>












  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("mpOMyFHLi7a5S0ka5mv3cz7C-gzGzoHsz", "3t0W0au9Mxf0lOGFDF8u89pc");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>
















</body>
</html>
